package cn.xscrum.demo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.demo.domain.Savetime;
import cn.xscrum.demo.service.ISavetimeService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 节省时间Controller
 * 
 * @author cyb
 * @date 2020-11-25
 */
@Controller
@RequestMapping("/demo/savetime")
public class SavetimeController extends BaseController
{
    private String prefix = "demo/savetime";

    @Autowired
    private ISavetimeService savetimeService;

    @RequiresPermissions("demo:savetime:view")
    @GetMapping()
    public String savetime()
    {
        return prefix + "/savetime";
    }

    /**
	 * 查询节省时间列表
     */
    @RequiresPermissions("demo:savetime:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Savetime savetime)
    {
        startPage();
        List<Savetime> list = savetimeService.selectSavetimeList(savetime);
        return getDataTable(list);
    }

    /**
	 * 导出节省时间列表
     */
    @RequiresPermissions("demo:savetime:export")
    @Log(title = "节省时间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Savetime savetime)
    {
        List<Savetime> list = savetimeService.selectSavetimeList(savetime);
        ExcelUtil<Savetime> util = new ExcelUtil<Savetime>(Savetime.class);
        return util.exportExcel(list, "savetime");
    }

    /**
	 * 新增节省时间
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存节省时间
     */
    @RequiresPermissions("demo:savetime:add")
    @Log(title = "节省时间", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Savetime savetime)
    {
        return toAjax(savetimeService.insertSavetime(savetime));
    }

    /**
	 * 修改节省时间
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Savetime savetime = savetimeService.selectSavetimeById(id);
        mmap.put("savetime", savetime);
        return prefix + "/edit";
    }

    /**
	 * 修改保存节省时间
     */
    @RequiresPermissions("demo:savetime:edit")
    @Log(title = "节省时间", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Savetime savetime)
    {
        return toAjax(savetimeService.updateSavetime(savetime));
    }

    /**
	 * 删除节省时间
     */
    @RequiresPermissions("demo:savetime:remove")
    @Log(title = "节省时间", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(savetimeService.deleteSavetimeByIds(ids));
    }
}
